﻿using FastReport;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static WinFormsApp1.SuYi.Week2WinForm.WaitingWinFormShow;
using WinFormsApp1.Common;
using System.Text.Json;


namespace WinFormsApp1.SuYi
{
    public partial class CheckDeail : Form
    {
        public CheckDeail()
        {
            InitializeComponent();
        }
        public string frx;
        public int PageIndex = 1;
        public int PageSize = 100;
        public string CheckInNo = "";
        public string QuarantineNo = "";
        public DateTime? EnterTime = null;
        public int SupplierId = 0;
        public int SettlementTypeId = 0;
        public string OriginAddr = "";
        private async void Form1_Load(object sender, EventArgs e)
        {
            Report report = new Report();
            if (!string.IsNullOrWhiteSpace(frx))
                report.Load(frx);


          

            //var item = await HttpClientHelper.RequestUrl<object, ApiResultFY2<List<CheckInDeailDto>>>("http://localhost:5106/api/Reports/", "QueryCheckDetail", HttpClientHelper.MethodType.POST, check);


            string url = URLCommon.Url2+@"/Reports/QueryCheckDetail";
            HttpClient client = new HttpClient();
            CheckInDeailDto check = new CheckInDeailDto();
            check.PageIndex = 1;
            check.PageSize = 100;
            check.CheckInNo = "";
            check.QuarantineNo = "";
            check.EnterTime = null;
            check.SupplierId = 0;
            check.SettlementTypeId = 0;
            check.OriginAddr = "";
            var content = new StringContent(JsonSerializer.Serialize<CheckInDeailDto>(check));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            var results = info["data"].Value<JToken>();
            var resultss = results["list"].Value<JArray>();

            //// 加载报表模板，这里假设模板文件是 "YourReportTemplate.frx"
            //report.Load(@".\FastREport模版\进场登记明细表\333.frx");
            //report.Load(@"E:\2203B专高六代码\333.frx");

            report.Load(@"../../../Reports\333.frx");
            DataSet ds = new DataSet();
            DataTable fr_dt = new DataTable();
            fr_dt.TableName = "baseInfos";
            fr_dt.Columns.Add("patName", typeof(String));//*****列名设置需要与标签模板一致*****
            fr_dt.Columns.Add("patset", typeof(String));
            fr_dt.Columns.Add("patone", typeof(String));
            fr_dt.Columns.Add("pattwo", typeof(String));
            fr_dt.Columns.Add("patthree", typeof(String));
            fr_dt.Columns.Add("patfour", typeof(String));
            fr_dt.Columns.Add("patfive", typeof(String));
            fr_dt.Columns.Add("patsix", typeof(String));
            fr_dt.Columns.Add("patsever", typeof(String));
            fr_dt.Columns.Add("pateight", typeof(String));
            fr_dt.Columns.Add("patnine", typeof(String));
            fr_dt.Columns.Add("patten", typeof(String));
            fr_dt.Columns.Add("topone", typeof(String));
            fr_dt.Columns.Add("toptwo", typeof(String));
            fr_dt.Columns.Add("topthree", typeof(String));
            fr_dt.Columns.Add("topfour", typeof(String));
            fr_dt.Columns.Add("topfive", typeof(String));
            fr_dt.Columns.Add("topsix", typeof(String));
            fr_dt.Columns.Add("topserver", typeof(String));

            for (int i = 0; i < resultss.Count; i++)
            {
                fr_dt.Rows.Add(resultss[i]["checkInId"], resultss[i]["liveAnimalsDate"], resultss[i]["checkInNo"], resultss[i]["carNo"], resultss[i]["settlementTypeName"], resultss[i]["supplierName"], resultss[i]["approachNum"], resultss[i]["quarantineNo"], resultss[i]["originAddr"], resultss[i]["checkInBatch"], resultss[i]["deliveryman"], resultss[i]["phone"], resultss[i]["identityCard"], resultss[i]["remark"], resultss[i]["enterTime"], resultss[i]["enterRegistrar"], resultss[i]["goOutTime"], resultss[i]["goOutRegistrar"], resultss[i]["checkInStateId"]);

            }
            ds.Tables.Add(fr_dt);
            report.RegisterData(ds);//将数据传递至标签模板

            //report.Print();//打印标签
            designerControl1.Report = report;
            //restore the design layout. Without this code, the designer tool windows will be unavailable
            designerControl1.RefreshLayout();

        }
        public void FastProt()
        {

            Report report = new Report();



        }

        public class CheckInDeailDto
        {  

            /// <summary>
            /// 进场登记时间
            /// </summary>
            public DateTime? EnterTime { get; set; }
            /// <summary>
            /// 供应商/养殖户 外健
            /// </summary>
            public int SupplierId { get; set; }
            /// <summary>
            /// 结算类型 外键
            /// </summary>
            public int SettlementTypeId { get; set; }
            /// <summary>
            /// 检疫证号
            /// </summary>
            [StringLength(100)]
            public string? QuarantineNo { get; set; }
            /// <summary>
            /// 产地
            /// </summary>
            [StringLength(100)]
            public string? OriginAddr { get; set; }
            /// <summary>
            /// 进场登记编号
            /// </summary>
            [StringLength(50)]
            public string? CheckInNo { get; set; }
            /// <summary>
            /// 页码
            /// </summary>
            public int PageIndex { get; set; }
            /// <summary>
            /// 条数
            /// </summary>
            public int PageSize { get; set; }
        }
    }
}
